package com.jifeng.sterilizer.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jifeng.sterilizer.entity.DeviceTypeEntity;
import com.jifeng.sterilizer.service.DeviceTypeService;
import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.R;


/**
 * 消毒机类型表
 *
 * @author jifeng
 * @email 1593140625@qq.com
 * @date 2020-07-26 15:15:14
 */
@RestController
@RequestMapping("sterilizer/devicetype")
public class DeviceTypeController {
    @Autowired
    private DeviceTypeService deviceTypeService;

    // 根据名字模糊查询消毒机类型的列表 PC
    @GetMapping("/pc/type/name/list")
    public R getListByName(@RequestParam Map<String, Object> params) {
        R rs = deviceTypeService.getListByName(params);
        return rs;
    }

    /**
     * 分页查询消毒机类型的列表 PC
     */
    @GetMapping("/pc/type/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = deviceTypeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Long id) {
        DeviceTypeEntity deviceType = deviceTypeService.getById(id);

        return R.ok().put("deviceType", deviceType);
    }

    /**
     * 新增消毒剂类型 PC
     * {"name":"空气消毒机","power":5,"flow":5,"memo":"NB"}
     */
    @PostMapping("/pc/type/add")
    public R save(@RequestBody DeviceTypeEntity deviceType) {
        boolean save = deviceTypeService.save(deviceType);
        if (save) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改消毒剂类型 PC
     */
    @PostMapping("/pc/type/update")
    public R update(@RequestBody DeviceTypeEntity deviceType) {
        boolean update = deviceTypeService.updateById(deviceType);
        if (update) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids) {
        deviceTypeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 逻辑删除消毒机类型 PC
     */
    @PostMapping("/pc/type/del")
    public R delete(@RequestBody Map<String, Object> params) {
        R rs = deviceTypeService.del(params);
        return rs;
    }

}
